
# generate figure 2

library(rio) # to load data
library(tidyverse) # to reshape data
library(zoo) # to work with dates
library(scales) # to make nice axis breaks
library(cowplot) # to arrange plots as grids

# set your working directory
setwd("~/replication_files")

import("data/monthly_data.csv") %>%
  mutate(date = as.yearmon(paste(month, year, sep = "/"), "%m/%Y")) %>%
  select(date,sovereign_issued_1yr_amount) %>%
  group_by(date) %>%
  summarise(sovereign_sum = round(sum(sovereign_issued_1yr_amount), 2),
            sovereign_sum = sovereign_sum/1000000000) %>% # in billions
  ggplot(aes(x = date, y=sovereign_sum)) + geom_col() + theme_classic() + 
  labs(x = "Year",y = "Billions of Constant US$") + 
  theme(axis.text = element_text(size = 12), plot.title = element_text(face = "bold"),
        axis.title = element_text(size = 12)) + scale_x_continuous(breaks = pretty_breaks())

ggsave("figures/figure2.pdf", height = 4, width = 7)

